package com.example.easyscript.dto.Resp;

import com.example.easyscript.bean.task.OperationBean;
import com.example.easyscript.bean.task.StatusBean;
import com.example.easyscript.bean.task.StepBean;
import com.example.easyscript.bean.task.TaskBean;
import com.example.easyscript.entity.task.Operation;
import lombok.Data;

import java.util.Map;

@Data
public class RunnerInfoReq {
    private Integer taskId;
    private String taskName;
    private Integer statusOrder;
    private String statusName;
    private Integer operationOrder;
    private String operationName;
    private Integer stepId;
    private String stepName;


    public RunnerInfoReq(TaskBean taskBean) {
        try {
            if(taskBean == null) return;
            final Map<Integer, StatusBean> stateBeanMap = taskBean.getStateDiagram().getStateBeanMap();
            StatusBean statusBean = stateBeanMap.get(taskBean.getCurrentStateSeq());
            this.taskId = taskBean.getId();
            this.taskName = taskBean.getTaskName() ;
            this.statusOrder = taskBean.getCurrentStateSeq() == null ? 0 : taskBean.getCurrentStateSeq();
            this.statusName = statusBean.getStatusName() == null ? "" : statusBean.getStatusName() ;
            this.operationOrder = taskBean.getTargetOperationSeq() == null ? 0 : taskBean.getTargetOperationSeq();
            if(taskBean.getCurrentOperationBean() != null){
                this.operationName = taskBean.getCurrentOperationBean().getOperationName();
                final StepBean stepBean = taskBean.getCurrentOperationBean().getStepBeanMap().get(taskBean.getTargetStepSeq());
                this.stepName = stepBean == null ? "" : stepBean.getStepName();
            }
            this.stepId = taskBean.getTargetStepSeq();
        }catch (Exception e){

        }
    }


}
